# 导包
from api.login import LoginAPI
from common.dbutil import DBUtil


# 创建测试类
class TestLoginAPI:

    def setup_class(self):
        # 初始化
        self.login_api = LoginAPI()
        # 1、获取图片验证码成功
        response = self.login_api.get_image_code(r=0.123456)
        assert 200 == response.status_code
        # 打印cookies数据
        print(response.cookies)
        print("-" * 80)
        TestLoginAPI.cookies666 = response.cookies

        # 2、获取短信验证码成功
        test_data = {
            "phone": "13327418533",
            "imgVerifyCode": "8888",
            "type": "reg"
        }
        response = self.login_api.get_phone_code(phone_data=test_data)
        print(response.json())

        #  清理数据
        DBUtil().exe_sql("DELETE from mb_member where phone='13327418533';")
        DBUtil().exe_sql("DELETE from mb_member_info where member_name='13327418533';")
        DBUtil().exe_sql("DELETE from mb_member_login_log where member_name='13327418533';")
        DBUtil().exe_sql("DELETE from mb_member_register_log where member_name='13327418533';")

    def test01_reg(self):
        test_data = {
            "phone": "13327418533",
            "password": "www13133",
            "verifycode": "8888",
            "phone_code": "666666",
            "dy_server": "on",
            "invite_phone": ""
        }
        response = self.login_api.reg(reg_data=test_data)
        print(response.json())

